var normalelapse = 1000;
var nextelapse = normalelapse; 
var finish = "00:00:01";
var timer = null;
// 开始运行
// 停止运行
function stop() {
window.clearTimeout(timer);
}
function onTimer()
 {            var clock=document.getElementById("clock");
              var start=clock.innerHTML;
               if (start == finish)
              {
             window.clearInterval(timer);
                             alert("该商品竞拍时间结束!请关注其他商品的拍卖。");
                  return;
                          }
         var hms = new String(start).split(":");
         var s = new Number(hms[2]);
         var m = new Number(hms[1]);
         var h = new Number(hms[0]);


         s -= 1;
         if (s < 0){
         s = 59;
         m -= 1;
             }
      if (m < 0){
      m = 59;
      h -= 1;
          }
      var ss = s < 10 ? ("0" + s) : s;
      var sm = m < 10 ? ("0" + m) : m;
      var sh = h < 10 ? ("0" + h) : h;
      start = sh + ":" + sm + ":" + ss;
      clock.innerText = start;
      if((sh==0)&&(sm==0)&&(s<15)){
		
		sendRequest();
	}
      // 清除上一次的定时器
      window.clearInterval(timer);
      // 自校验系统时间得到时间差, 并由此得到下次所启动的新定时器的时间nextelapse
      if (nextelapse < 0) nextelapse = 0;
      // 启动新的定时器
      timer = window.setInterval("onTimer()", nextelapse); 
  }
var request;
function createXMLRequest(){
	if(window.ActiveXObject){
		request=new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		//alert("This is FireFox !");
		request=new XMLHttpRequest();
	}else{
		alert("你请求的对象不存在！");
	}
}
   
function processResult1(){
         
		if(request.readyState==4){
			
			if(request.status==200){
			 
				  callBack(request.responseText);
			}else { 
                alert("Problem: " + request.statustext); 
            } 
		}
}       
       

function updateRecord(){

    var	auctionid=document.getElementById("pro");
	var auctionId=auctionid.value;
	
	
	var url='/duojinV1//updateRecord.do?operation=update&auctioningId='+auctionId;
	
	createXMLRequest();
	request.onreadystatechange=processResult1;
	request.open("GET",url,true);
	request.send(null);
}

function callBack(data){
     var dtable = document.getElementById('record');
     
     var nl = request.responseXML.getElementsByTagName('acurecord');
     delText(dtable);
   
     var remainTime = request.responseXML.getElementsByTagName('remainTime');
     
     clock.innerText=remainTime.item(0).firstChild.nodeValue;
     for(var i = 0; i < nl.length; i++){
         var nli = nl.item(i);
         
         var elpr = nli.getElementsByTagName('price');
         var valueelpr = elpr.item(0).firstChild.nodeValue;
         
         var elName = nli.getElementsByTagName( 'userName' );
         var valueName = elName.item(0).firstChild.nodeValue;
         
         var eltime = nli.getElementsByTagName( 'time' );
         var valuetime = eltime.item(0).firstChild.nodeValue;
         
         //在table中新建一行
         var elTr = dtable.insertRow( -1 );
         
         var idTd = elTr.insertCell( -1 );
         idTd.innerHTML = valueelpr;
         
         var idTd = elTr.insertCell( -1 );
         idTd.innerHTML = valueName;
         
         var idTd = elTr.insertCell( -1 );
         idTd.innerHTML = valuetime;
     }
  
    
}

function delText(dtable)
{
  
  for(var i=0;i<dtable.childNodes.length;)
  {
  
    if(dtable.childNodes[i])
    {  
        dtable.removeChild(dtable.childNodes[i]);
        
    }
    else     
    { 
        i++;
    }
  }
      
}


